package com.azusa.xbiao.service.impl;

import com.azusa.xbiao.dao.ResourceDao;
import com.azusa.xbiao.entity.Resource;
import com.azusa.xbiao.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private ResourceDao resourceDao;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<Resource> findAll(){
        List<Resource> o = (List<Resource>) redisTemplate.opsForValue().get("com.azusa.xbiao.service.impl.ResourceServiceImpl.findAll");
        if (o==null){
            o = resourceDao.findAll();
            redisTemplate.opsForValue().set("com.azusa.xbiao.service.impl.ResourceServiceImpl.findAll",o,1, TimeUnit.DAYS);

        }
        return o;
    }

}
